
function TaskDTO() {

	this.setColor("#aaaaaa");
	
	this.setStartDate(new Date());
	this.setDuration(30);
	
	this.tasks = new Array();
}

TaskDTO.prototype.setId = function(id) {
	this.id = id;
}

TaskDTO.prototype.getId = function() {
	return this.id;
}

TaskDTO.prototype.setTitle = function(title) {
	this.title = title;
}

TaskDTO.prototype.getTitle = function() {
	return this.title;
}

TaskDTO.prototype.setDescription = function(description) {
	this.description = description;
}

TaskDTO.prototype.getDescription = function() {
	return this.description;
}

TaskDTO.prototype.setStartDate = function(date) {
	this.startDate = date;
}

TaskDTO.prototype.getStartDate = function() {
	var startDate = this.startDate;
	
	var previousTask = this.getPreviousTask();
	if(previousTask!=null) {
		startDate = previousTask.getFinishDate();
	} else {
		var parentTask = this.getParentTask();
		if(parentTask!=null) {
			startDate = parentTask.getStartDate();
		}
	}

	return startDate;
}

TaskDTO.prototype.getFinishDate = function() {
	var startDate = this.getStartDate();
	var finishDate = new Date();
	finishDate.setTime(startDate.getTime() + (this.getDuration() * 60 * 1000));
	return finishDate;
}

TaskDTO.prototype.setDuration = function(duration) {
	this.duration = duration;
}

TaskDTO.prototype.getDuration = function() {
	return this.duration;
}

TaskDTO.prototype.setColor = function(color) {
	this.color = color;
}

TaskDTO.prototype.getColor = function() {
	return this.color;
}

TaskDTO.prototype.setPreviousTask = function(previousTask) {
	this.previousTask = previousTask;
}

TaskDTO.prototype.getPreviousTask = function() {
	return this.previousTask;
}

TaskDTO.prototype.setParentTask = function(parentTask) {
	this.parentTask = parentTask;
}

TaskDTO.prototype.getParentTask = function() {
	return this.previousTask;
}

TaskDTO.prototype.isParentTaskOf = function(childTask) {
	var isParent = false;

	if(childTask.getParentTask()!=null) {
		if(childTask.getParentTask()==this) {
			isParent = true;
		} else {
			isParent = this.isParentTaskOf(childTask.getParentTask());
		}
	}
	
	return isParent;
}

TaskDTO.prototype.addTask = function (childTask) {
	this.tasks[this.tasks.length] = childTask;
	childTask.setParentTask(this);
}

TaskDTO.prototype.getTasks = function () {
	return this.tasks;
}
